package com.example.module_maintenance.viewmodel

import androidx.lifecycle.MutableLiveData
import com.bw.lib_common.coroutine.CoroutineHelper
import com.bw.lib_common.vm.BaseViewModel2
import com.example.module_maintenance.entity.RepairEntity
import com.example.module_maintenance.repo.RepairRepo
import kotlinx.coroutines.launch

class RepairViewModel : BaseViewModel2<RepairRepo>() {

    val getRepairSuccess by lazy { MutableLiveData<List<RepairEntity>>() }

    fun getRepair() {
        CoroutineHelper.mViewModelScope.launch(CoroutineHelper.mDispatcher) {
            val result = mRepository.getRepair()
            if (result.code == 200) {
                getRepairSuccess.postValue(result.data)
            }else{
                mErrorLiveData.postValue("获取数据异常")
            }
        }
    }

    val addRepairSuccess by lazy { MutableLiveData<RepairEntity>() }
    fun addRepair(body:RepairEntity){
        CoroutineHelper.mViewModelScope.launch(CoroutineHelper.mDispatcher){
            val result = mRepository.addRepair(body)
            if (result.code==200){
                addRepairSuccess.postValue(result.data)
            }else{
                mErrorLiveData.postValue("添加失败")
            }
        }
    }






    override fun createRepository(): RepairRepo = RepairRepo()


}